def smallest_subarray_with_given_sum(s, arr):
  # TODO: Write your code here
  _sum = 0
  min_length = len(arr)+10
  length = 0
  start = 0
  # print("input"+str(arr))
  for end in range(len(arr)):
    _sum += arr[end]
    length += 1
    while(_sum>s):
      _sum -= arr[start]
      if(_sum<s):
        min_length = min(length,min_length)
        print("arr:"+str(arr[start:end+1]))
      elif(_sum == s):
        min_length = min(length-1,min_length)
        print("arr:"+str(arr[start+1:end+1]))
      start += 1
      length -= 1

  return min_length


def main():
  print("Smallest subarray length: " + str(smallest_subarray_with_given_sum(7, [2, 1, 5, 2, 3, 2])))
  print("Smallest subarray length: " + str(smallest_subarray_with_given_sum(7, [2, 1, 5, 2, 8])))
  print("Smallest subarray length: " + str(smallest_subarray_with_given_sum(8, [3, 4, 1, 1, 6])))


main()